﻿<ad:DocumentContent x:Class="WPFToolboxForSiemensPLCs.DockableWindows.ContentWindowFunctionBlockEditor"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
                    xmlns:avalonEdit="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit"
                    xmlns:Blocks="clr-namespace:DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks;assembly=DotNetSiemensPLCToolBoxLibrary"
                    xmlns:Converters="clr-namespace:JFKCommonLibrary.WPF.Converters;assembly=JFKCommonLibrary"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:NetworkEditor="clr-namespace:WPFToolboxForSiemensPLCs.Controls.NetworkEditor"
                    Closing="DocumentContent_Closing"
                    d:DesignHeight="339"
                    d:DesignWidth="482"
                    IsActiveDocumentChanged="DocumentContent_IsActiveDocumentChanged"
                    mc:Ignorable="d">
    <ad:DocumentContent.Resources>
        <Style TargetType="ListBoxItem">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue" />
            </Style.Resources>
        </Style>
        <Converters:ItemLineNumbersConverter x:Key="ItemLineNumbersConverter" />
        <ControlTemplate x:Key="TemplateEditor"
                         x:Name="TemplateEditor"
                         TargetType="avalonEdit:TextEditor">
            <ScrollViewer Name="PART_ScrollViewer"
                          HorizontalContentAlignment="Left"
                          VerticalContentAlignment="Top"
                          Background="{TemplateBinding Control.Background}"
                          BorderBrush="{TemplateBinding Control.BorderBrush}"
                          BorderThickness="{TemplateBinding Control.BorderThickness}"
                          CanContentScroll="True"
                          Content="{Binding Path=TextArea,
                                            RelativeSource={RelativeSource TemplatedParent}}"
                          Focusable="False"
                          HorizontalScrollBarVisibility="Hidden"
                          Padding="{TemplateBinding Control.Padding}"
                          VerticalScrollBarVisibility="Hidden" />
            <ControlTemplate.Triggers>
                <Trigger Property="avalonEdit:TextEditor.WordWrap" Value="True">
                    <Setter TargetName="PART_ScrollViewer" Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </ad:DocumentContent.Resources>
    <Grid Name="mainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="0.3*" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Name="toppanel" Grid.Row="0">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="180" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TreeView Name="myTree"
                      Grid.Column="0"
                      ItemsSource="{Binding}"
                      SelectedItemChanged="myTree_SelectedItemChanged">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                        <TextBlock Text="{Binding Name}" />
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
            <GridSplitter Grid.Column="0" Width="5" />
            <DataGrid Name="myDGrid"
                      Grid.Column="1"
                      AutoGenerateColumns="False"
                      DockPanel.Dock="Right"
                      ItemsSource="{Binding Children}">
                <DataGrid.Columns>
                    <DataGridTextColumn MinWidth="30"
                                        Binding="{Binding BlockAddress}"
                                        CanUserSort="False"
                                        Header="Address" />
                    <DataGridTextColumn MinWidth="100"
                                        Binding="{Binding Name}"
                                        CanUserSort="False"
                                        Header="Name" />
                    <DataGridTextColumn MinWidth="80"
                                        Binding="{Binding DataTypeAsString}"
                                        CanUserSort="False"
                                        Header="Datatype" />
                    <DataGridTextColumn MinWidth="80"
                                        Binding="{Binding StartValue}"
                                        CanUserSort="False"
                                        Header="StartValue" />
                    <DataGridTextColumn Width="300"
                                        MinWidth="100"
                                        Binding="{Binding Comment}"
                                        CanUserSort="False"
                                        Header="Comment" />
                </DataGrid.Columns>
            </DataGrid>

        </Grid>
        <GridSplitter Grid.Row="1"
                      Grid.Column="0"
                      Grid.ColumnSpan="2"
                      Width="Auto"
                      Height="5"
                      Margin="0"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      ResizeDirection="Rows" />

        <!--
            <avalonEdit:TextEditor  Grid.Row="2"
            Name="textEditor"
            FontFamily="Consolas"
            FontSize="10pt"
            ShowLineNumbers="True" MouseHover="textEditor_MouseHover" MouseHoverStopped="textEditor_MouseHoverStopped" Visibility="Visible"></avalonEdit:TextEditor>
        -->
        <ListBox Name="myLst"
                 Grid.Row="2"
                 HorizontalAlignment="Stretch"
                 HorizontalContentAlignment="Stretch"
                 ScrollViewer.CanContentScroll="False"
                 ScrollViewer.ScrollChanged="ScrollChanged">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <NetworkEditor:NetworkEditor DisplayNetwork="{Binding}" NetworkNumber="{Binding Converter={StaticResource ItemLineNumbersConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>

</ad:DocumentContent>
